<template>
	<view>
		<preview :userinfo="userInfo"></preview>
		<view v-if="type == '1'" class="opr-aera">
			<view>
				<u-icon v-if="status <= 1" name="weixin-fill" label="获取联系" size="20" bold color="#00ad19"
					labelColor="#00ad19" @click="getContact"></u-icon>
				<u-icon v-else name="weixin-fill" label="获取联系" size="20" bold color="#dadbde" labelColor="#dadbde">
				</u-icon>
			</view>
			<view>
				<u-icon v-if="status <= 1" name="person-delete-fill" label="拒绝" size="20" bold color="#e23d30"
					labelColor="#e23d30" @click="showRejModal = true"></u-icon>
				<u-icon v-else name="person-delete-fill" label="拒绝" size="20" bold color="#dadbde" labelColor="#dadbde">
				</u-icon>
			</view>

		</view>
		<u-modal :show="showRejModal" @confirm="confirmshowPicker" ref="uModal" :closeOnClickOverlay="true"
			showCancelButton @cancel="showRejModal=false" @close="showRejModal=false" title='确定要拒绝此人的投递吗'></u-modal>
		<u-picker :columns="columns" :show="showpicker" @cancel="showpicker = false" closeOnClickOverlay="true"
			@close="showpicker= false" @confirm="selectReason">
		</u-picker>
	</view>
</template>

<script>
	import {
		userinfo,
		updateResustatus,
		resustatus,
		contact
	} from "@/common/http.api.js"
	import preview from '@/pages/editInfo/preview.vue'
	export default {
		components: {
			preview
		},
		data() {
			return {
				status: '',
				userId: '',
				_id: '',
				type: '',
				reason: '',
				userInfo: {},
				columns: [
					['不合适', '已满人']
				],
				showpicker: false,
				showRejModal: false,
				show: false
			}
		},
		onLoad(options) {
			// console.log(options);
			this.userId = options.userId
			this.type = options.type || '0'
			this._id = options._id || ''
			if (this._id) {
				// console.log('ok');
				this.getResuStatus()
				if (this.status == 0) this.updateResuStatus('1') // 改已读
			}
			this.getuserinfo()
		},
		methods: {
			async getuserinfo() {
				const res = await userinfo({
					userId: this.userId
				})
				if (res.code === 0) this.userInfo = res.data

			},
			async updateResuStatus(status) {
				const res = await updateResustatus({
					_id: this._id,
					status: status,
					reason: this.reason
				})

			},
			async getResuStatus() {
				const res = await resustatus({
					_id: this._id
				})
				this.status = Number(res.data.status)
				// console.log(res.data.status);
			},
			async selectReason(arr) {
				this.reason = arr.value[0]
				await this.updateResuStatus('3')
				this.showpicker = false
				uni.$showMsg('已拒绝')
				// 重新获取状态
				this.$nextTick(() => {
					this.getResuStatus()
				})
			},
			async getContact() {
				const res = await contact({
					userId: this.userId
				})
				this.contact = res.data.contact
				this.copyContact(this.contact)
				await this.updateResuStatus('2')
				this.$nextTick(() => {
					this.getResuStatus()
				})
			},
			copyContact(value) {
				uni.setClipboardData({
					data: value,

				});
				uni.getClipboardData({
					success: function(res) {
						uni.showToast({
							title: "获取成功，已复制到剪贴板",
							icon:'none'
						});
					},
				});
			},
			confirmshowPicker() {
				this.showRejModal = false
				this.$nextTick(() => {
					this.showpicker = true
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	.opr-aera {
		padding-top: 25rpx;
		display: flex;
		justify-content: space-around;
		align-items: baseline;
		z-index: 99;
		position: fixed;
		bottom: 0;
		height: 120rpx;
		width: 100%;
		background-color: #fff;
		border-top: 1rpx solid #eee;
		padding-bottom: constant(safe-area-inset-bottom);
	}
</style>
